def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def closest_prime_number(num):
    if is_prime(num):
        return num

    lower = num - 1
    upper = num + 1
    while True:
        if lower >= 2 and is_prime(lower):
            return lower
        elif is_prime(upper):
            return upper
        lower -= 1
        upper += 1


def word_to_number(word):
    numbers = {
        "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4,
        "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9
    }
    return numbers.get(word, None)


input_words = input().split()
if len(input_words) != 3:
    print("Wrong input")
else:
    numbers = [word_to_number(word) for word in input_words]
    if None in numbers:
        print("Wrong input")
    else:
        num = int("".join(str(n) for n in numbers))
        if 100 <= num <= 999:
            print(closest_prime_number(num))
        else:
            print("Wrong input")
